<template>
  <!-- 考试记录 -->
  <div class="app-container">
    <!-- <h1> 考试记录</h1> -->

    <div class="boxlaw">
      <div class="comform">
        <ComForm
          ref="comForm"
          @EventReset="resetFn"
          @EventOnsubmit="queryFn"
          :list="comForm"
        >
        </ComForm>
      </div>

      <ComTable
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
        <el-table-column #default="{ row }" align="left">
          <template v-if="row.reslut == 1">
            <!-- "
              $router.push({
                path: '/contentPlatform/laws/laws-details',
                query: row,
              })
            " -->
            <!-- v-hasPermi="['base:docModule:list']" -->
            <span>-</span>
          </template>
          <template v-else-if="row.reslut == 2">
            <el-button
              @click="
                $router.push({
                  query: row,
                })
              "
              plain
              size="mini"
              reslut="primary"
              >提醒考试</el-button
            >
          </template>
        </el-table-column>
      </ComTable>
    </div>
  </div>
</template>

<script>
import ComForm from "../../../components/comForm.vue";
import ComSelect from "../../../components/comSelect.vue";
import ComTable from "../../../components/comTable.vue";
import comForm from "../../../components/comForm.vue";
// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision.js";

import { getExamHistoryListApi } from "@/wss/api/HumanResources/EM/record.js";
export default {
  name: "Question",

  components: { ComSelect, ComForm, comForm, ComTable },

  data() {
    return {
      initSelectValue: "",
      // 加载
      loading: false,
      paging: {
        pageNum: 1,
        pageSize: 10,
        reslut: "",
        createType: "",
        createNo: "",
        createTime: null,
        createName: "",
      },
      // 切换筛选状态，不更新bug修复
      random: "",
      // 当前筛选的状态
      currentSelect: "",

      // 动态生成下拉列表的筛选条件
      dynamicFilter: {},
      // 表格的数据
      tableList: [],
      // 表格渲染字段
      tableModes: [
        {
          label: "工号",
          mode: "createNo",
        },
        {
          showOverflowTooltip: true,
          width: 200,
          label: "姓名",
          mode: "createName",
          showOverflowTooltip: true,
        },
        {
          label: "角色",
          mode: "createType",
          effectiveStatus: true,
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "专家",
              v: 1,
            },
            {
              l: "商务 ",
              v: 2,
            },
          ],
        },
        {
          label: "已考次数",
          mode: "number",
          showOverflowTooltip: true,
        },
        {
          label: "分数",
          mode: "score",
          width: 100,
          align: "center",
        },
        {
          label: "考试时长",
          mode: "time",
        },
        {
          label: "状态",
          mode: "reslut",
          effectiveStatus: true,
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "通过",
              v: 1,
            },
            {
              type: "danger",
              l: "未通过",
              v: 2,
            },
          ],
        },

        {
          label: "末次考试时间",
          mode: "createTime",
        },
      ],
      comForm: {
        modes: [
          {
            placeholder: "请输入工号",
            formType: "input",
            mode: "createNo",
            label: "工号",
            value: "",
          },
          {
            placeholder: "请输入姓名",
            formType: "input",
            mode: "createName",
            label: "姓名",
            value: "",
          },
          {
            formType: "select",
            mode: "createType",
            label: "角色",
            value: "",
            select: [],
          },

          {
            placeholder: "",
            formType: "select",
            mode: "reslut",
            label: "状态",
            value: "",
            select: [],
          },
          {
            placeholder: "请选择日期",
            formType: "date",
            mode: "createTime",
            label: "考试日期",
            value: null,
            pickerType: "datetime",
          },
        ],
      },
    };
  },

  mounted() {
    this.getExamHistoryListApiFn(this.paging);
  },
  methods: {
    // 重设函数
    resetFn() {
      this.initSelectValue = "";
      this.romdom = Math.random();
    },
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getExamHistoryListApiFn(this.paging);
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getExamHistoryListApiFn(this.paging);
    },
    // 筛选数据
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.currentSelect = this.initSelectValue;

      this.paging.pageNum = 1;
      console.log(this.paging, "查询");
      this.getExamHistoryListApiFn(this.paging);
    },
    // 获取列表数据
    async getExamHistoryListApiFn(pagination = null) {
      this.loading = true;
      let result = await getExamHistoryListApi(pagination);

      console.log(result, "考试记录的数据");
      if (result.code == 200) {
        this.tableList = result.rows;
        this.paging.total = result.total;
        // 把后端放回的字段变成下拉筛选字段
        this.tableList.forEach((item) => {
          //是否有这个属性
          this.dynamicFilter.createType
            ? ""
            : (this.dynamicFilter.createType = []);

          this.dynamicFilter.reslut ? "" : (this.dynamicFilter.reslut = []);

          if (!this.dynamicFilter.createType.includes(item.createType)) {
            this.dynamicFilter.createType.push(item.createType);
          }

          if (!this.dynamicFilter.reslut.includes(item.reslut)) {
            this.dynamicFilter.reslut.push(item.reslut);
          }
        });

        this.comForm.modes.forEach((item) => {
          switch (item.mode) {
            case "createType":
              item.select = this.arrTransformObj(
                this.dynamicFilter.createType,
                ["", "专家", "商务"]
              );
              break;
            case "reslut":
              // item.select = this.arrTransformObj(this.dynamicFilter.reslut);
              //
              item.select = this.arrTransformObj(this.dynamicFilter.reslut, [
                "",
                "通过",
                "未通过",
              ]);
              break;
            case "scope":
              item.select = this.arrTransformObj(this.dynamicFilter.scope);
              break;

            default:
              break;
          }
        });

        this.loading = false;
      }
    },

    // 查看
    async clickLook(row) {
      if (row.status == 2) {
        this.$router.push({
          path: "/contentPlatform/laws/laws-failReason",
          query: { id: row.idStr },
        });
      } else {
        this.$router.push({
          path: "/contentPlatform/laws/laws-details",
          query: { id: row.idStr },
        });
      }
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>